package com.nexgo.payment.trans.operator.add;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.nexgo.payment.R;
import com.nexgo.payment.databases.Repository;
import com.nexgo.payment.ui.BaseActivity;
import com.nexgo.payment.util.ToastUtils;
import com.nexgo.payment.util.UIUtils;
import com.nexgo.payment.widget.TitleBuilder;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 添加操作员界面
 *
 * @author 谭忠扬-YuriTam
 * @time 2017年8月7日
 */
public class OperatorAddActivity extends BaseActivity implements OperatorAddContract.View {
    private static final String TAG = OperatorAddActivity.class.getSimpleName();

    @BindView(R.id.et_operator_no)
    EditText etOperatorNo;
    @BindView(R.id.et_password)
    EditText etPassword;

    private OperatorAddPresenter mPresenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add_operator);
        ButterKnife.bind(this);

        initTitle();
        new OperatorAddPresenter(this, Repository.getInstance());
    }

    //初始化标题栏
    private void initTitle() {
        new TitleBuilder(this)
                .setExternalTitleBgRes(R.drawable.bg_blue_icon)
                .setLeftImage(R.drawable.arrow_icon)
                .setRightText(getString(R.string.action_save))
                .setTitleText(getString(R.string.operator_add_title))
                .build();
    }

    @OnClick({R.id.title_iv_left, R.id.title_tv_right})
    public void onClicked(View view) {
        if (UIUtils.isDoubleClick()) {
            return;
        }
        UIUtils.hideSoftKeyboard(this);
        switch (view.getId()) {
            case R.id.title_iv_left:
                finish();
                break;
            case R.id.title_tv_right:
                mPresenter.addOperator(etOperatorNo.getText().toString().trim(), etPassword.getText().toString().trim());
                break;
            default:
                break;
        }
    }

    @Override
    public void setPresenter(OperatorAddPresenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public void showTips(String message) {
        ToastUtils.showToast(message);
    }

    @Override
    public void showSuccess() {
        Intent intent = new Intent();
        setResult(1000,intent);
        finish();
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.slide_left_in, R.anim.slide_right_out);
    }
}
